/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-04-17 15:38:47
 * @LastEditTime : 2023-09-07 19:50:37
 * @LastEditors  : 飞越疯人院 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Modal\ModalBox.jsx
 * @Description  :
 */
import './Scss/ModalBox.scss'
import { Modal, Drawer } from 'antd'
import { useBoolean } from 'ahooks'
import { useEffect, useState } from 'react'
// 加载弹窗模板
import {
    ThemeTypeSelect,
    ThemeBackImageSelect,
    ThemeColor,
    HeaderOptionsSet,
    HeaderUserInfoSet,
} from './ModalList/ThemeList'
import { PanTiltControl, PanPlaybackVideo } from './ModalList/CameraList'
import {
    SelectModal,
    InputModal,
    ModifyPassWord,
    Multiple,
    LabHandling,
    SwitchProjects,
    SynchronizeScore,
    MapPositionModal,
    AIPicturesModal,
} from './ModalList/OptionsList'
import {
    LabStressMachine,
    LineChartsModal,
    LabUniversalRebar,
    CementMixingStations,
    LabAsphalt,
    TAPMate,
    TAPDetails,
    LabAsphaltCentralized,
    LabCoverProtector,
    LabReboundHammer,
} from './ModalList/TestDataList'
import {
    Annex,
    PrintQRcode,
    OpenExcel,
    MonitorVideo,
    OrdinaryQRCode,
    RichTextEditor,
    AnnexMore,
    ZLVideoModal,
    MonitoringModal,
    FileManagement,
    UrlQRCode,
    SciencesDetails,
} from './ModalList/AnnexList'
import {
    Add,
    Mod,
    Del,
    ProjectFormItemValue,
    MonthReportAttachment,
    CompanyAttachment,
    BaDaFilingCabinet,
    BaDaFilingCabinetDetails,
    BaDaFilingCabinetForm,
    BaDaFilingCabinetConfiguration,
    BadaBatchAdd,
    YearMonthSelectModal,
} from './ModalList/FormList'

import { TwoRouter, ThrRouter } from '../Router/MenuNav/module/RouterList'
import {
    FlowChartModal,
    FlowChartDetail,
    FlowChartRecords,
    FlowChartApprovalStatus,
    FlowFormSubmitModal,
} from './ModalList/FlowChart'

import { FenceMapModal } from './ModalList/Mars3dList'

const ThemeList = { ThemeTypeSelect, ThemeBackImageSelect, ThemeColor, HeaderOptionsSet, HeaderUserInfoSet }
const CameraList = { PanTiltControl, PanPlaybackVideo }
const OptionsList = {
    SelectModal,
    InputModal,
    ModifyPassWord,
    Multiple,
    LabHandling,
    SwitchProjects,
    SynchronizeScore,
    MapPositionModal,
    AIPicturesModal,
}
const TestDataList = {
    LabStressMachine,
    LineChartsModal,
    LabUniversalRebar,
    CementMixingStations,
    LabAsphalt,
    TAPMate,
    TAPDetails,
    LabAsphaltCentralized,
    LabCoverProtector,
    LabReboundHammer,
}
const AnnexList = {
    Annex,
    PrintQRcode,
    OpenExcel,
    MonitorVideo,
    OrdinaryQRCode,
    RichTextEditor,
    AnnexMore,
    ZLVideoModal,
    MonitoringModal,
    FileManagement,
    UrlQRCode,
    SciencesDetails,
}
const FormList = {
    Add,
    Mod,
    Del,
    ProjectFormItemValue,
    MonthReportAttachment,
    CompanyAttachment,
    BaDaFilingCabinet,
    BaDaFilingCabinetDetails,
    BaDaFilingCabinetForm,
    BaDaFilingCabinetConfiguration,
    BadaBatchAdd,
    YearMonthSelectModal,
}
const RouterList = { TwoRouter, ThrRouter }

const FlowChart = { FlowChartModal, FlowChartDetail, FlowChartRecords, FlowChartApprovalStatus, FlowFormSubmitModal }

const ModalList = { FenceMapModal }

export const ModalBox = ({ ModalEvent, OptionsCall, actionRef, configure, reloadEvent }) => {
    const ModalListData = {
        ...ThemeList,
        ...CameraList,
        ...OptionsList,
        ...TestDataList,
        ...AnnexList,
        ...FormList,
        ...RouterList,
        ...FlowChart,
        ...ModalList,
    }
    const [Open, { setTrue, setFalse }] = useBoolean(false)
    const [Type, setType] = useState()
    const [Data, setData] = useState()

    useEffect(() => {
        if (OptionsCall) {
            setType(OptionsCall.type)
            setData(OptionsCall.data)
            setTrue()
        }
    }, [OptionsCall, setTrue])

    const ModalTemplate = () => (
        <Modal
            className="ModalBox"
            open={Open}
            footer={null}
            maskClosable={false}
            onCancel={setFalse}
            destroyOnClose
            title={Data?.title || '操作弹窗'}
            width={Data?.width || 1000}
            centered
        >
            {(() => {
                if (!Type) return false
                const Template = ModalListData[Type]
                return (
                    <Template
                        ModalEvent={ModalEvent}
                        data={Data}
                        Off={setFalse}
                        actionRef={actionRef}
                        configure={configure}
                        reloadEvent={reloadEvent}
                    />
                )
            })()}
        </Modal>
    )

    const DrawerTemplate = () => (
        <Drawer
            className="DrawerBox"
            open={Open}
            placement="right"
            onClose={setFalse}
            title={Data?.title || '操作弹窗'}
            width={Data?.width || 1000}
            destroyOnClose
        >
            {(() => {
                if (!Type) return false
                const Template = ModalListData[Type]
                return <Template data={Data} actionRef={actionRef} Off={setFalse} configure={configure} />
            })()}
        </Drawer>
    )

    return <>{Type === 'ThrRouter' ? <DrawerTemplate /> : <ModalTemplate />}</>
}
